Imports System.Data
Partial Class elenco
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents btFascicolo As System.Web.UI.WebControls.Button
    Protected WithEvents btFascicolo2 As System.Web.UI.WebControls.Button


    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region





    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        If Not Page.IsPostBack Then

            If Not UcTestata1.carica() Then
                Response.Redirect("..\errore.htm")
            End If

            Dim obj As New cConfigura(False)

            lbDesc.Text = obj.conf.descAlbo


            Session("risultato") = Nothing
            ViewState("img") = "imgNome"
            ViewState("ordine") = "nominativo "
            ViewState("sort") = " "

            aggGrid()

        End If

    End Sub


    Private Sub aggGrid()
        Dim obj As New AnaPraticanti
        Dim dtPrat As DataTable

        Dim tipoRicerca As String = ddlTipoRicerca.SelectedItem.Value

        dtPrat = obj.elencoPraticanti(ViewState("ordine") & " " & ViewState("sort"), ViewState("filtro"), rdTutti.SelectedValue, tipoRicerca)

        Session("risultato") = dtPrat
        dgPrat.CurrentPageIndex = 0
        dgPrat.DataSource = dtPrat
        dgPrat.DataBind()

    End Sub

    Private Sub aggGridperNumero()
        Dim obj As New AnaPraticanti
        Dim dtPrat As DataTable

        dtPrat = obj.elencoPraticantiPerNumero(ViewState("ordine") & " " & ViewState("sort"), ViewState("filtro"), rdTutti.SelectedValue, "")

        Session("risultato") = dtPrat
        dgPrat.CurrentPageIndex = 0
        dgPrat.DataSource = dtPrat
        dgPrat.DataBind()


    End Sub

    Private Sub dgPrat_ItemCreated(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgPrat.ItemCreated
        If e.Item.ItemType = ListItemType.Header Then

            If (ViewState("ordine") <> "" And ViewState("img") <> "") Then
                Dim imgB As ImageButton = e.Item.FindControl(ViewState("img"))
                If ViewState("sort") = " ASC" Then
                    imgB.ImageUrl = "../images/q_ord_up.gif"
                Else
                    imgB.ImageUrl = "../images/q_ord_down.gif"
                End If

            End If

        End If
    End Sub

    Private Sub dgPrat_ItemCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgPrat.ItemCommand
        Select Case e.CommandName


            Case "vedi"
                Dim objAnaPrat As AnaPrat = New AnaPraticanti(True).Anagrafica
                Dim objAna As Anagrafica = New Anagrafiche(True).Anagrafica
                objAna.idAna = dgPrat.Items(e.Item.ItemIndex).Cells(4).Text
                objAna.tipo = 1
                objAnaPrat.idAna = objAna.idAna
                objAnaPrat.idPrat = dgPrat.Items(e.Item.ItemIndex).Cells(3).Text
                objAna.carica()
                objAnaPrat.caricaPrat()

                objAna.numElenco = (dgPrat.PageSize * dgPrat.CurrentPageIndex) + e.Item.ItemIndex
                Response.Redirect("scheda.aspx")

            Case "pg_prec"
                dgPrat.CurrentPageIndex = dgPrat.CurrentPageIndex - 1
                dgPrat.DataSource = Session("risultato")
                dgPrat.DataBind()

            Case "pg_succ"
                dgPrat.CurrentPageIndex = dgPrat.CurrentPageIndex + 1
                dgPrat.DataSource = Session("risultato")
                dgPrat.DataBind()
        End Select

    End Sub

    Private Sub dgPrat_PageIndexChanged(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgPrat.PageIndexChanged
        dgPrat.CurrentPageIndex = e.NewPageIndex
        dgPrat.DataSource = Session("risultato")
        dgPrat.DataBind()
    End Sub



    Protected Sub ordina_nome(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        apriAna.Value = 0

        ViewState("img") = CType(sender, ImageButton).ID
        If ViewState("ordine") <> "nominativo" Then
            ViewState("sort") = " ASC"
            ViewState("ordine") = "nominativo"
        Else
            If ViewState("sort") = " ASC" Then
                ViewState("sort") = " DESC"
            Else
                ViewState("sort") = " ASC"
            End If
        End If

        If txNumero.Text = "" Then
            aggGrid()
        Else
            aggGridperNumero()
        End If
    End Sub

    Protected Sub ordina_num(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        apriAna.Value = 0

        ViewState("img") = CType(sender, ImageButton).ID
        If ViewState("ordine") <> "num_isc" Then
            ViewState("sort") = " ASC"
            ViewState("ordine") = "num_isc"
        Else
            If ViewState("sort") = " ASC" Then
                ViewState("sort") = " DESC"
            Else
                ViewState("sort") = " ASC"
            End If
        End If

        If txNumero.Text = "" Then
            aggGrid()
        Else
            aggGridperNumero()
        End If
    End Sub


    Private Sub rdTutti_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdTutti.SelectedIndexChanged
        aggGrid()
    End Sub

    Private Sub stampa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Response.Redirect("..\rep\report.aspx")
    End Sub

    Private Sub lkIscritti_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lkIscritti.Click
        Response.Redirect("..\iscritti\elencoI.aspx")
    End Sub

    Private Sub btNew_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btNew.ServerClick
        Dim anag As New Anagrafiche(True)
        Dim anagPrat As New AnaPraticanti(True)
        anagPrat.Anagrafica.numIsc = anagPrat.Anagrafica.getNumero
        anag.Anagrafica.tipo = 1   'praticante
        anag.Anagrafica.numElenco = -1
        apriAna.Value = 1

    End Sub

    Private Sub lkStat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lkStat.Click
        Dim obj = New Statistiche(True).Statistica

        Response.Redirect("..\report\stat.aspx?t=1&storico=" & rdTutti.SelectedValue)
    End Sub

    Private Overloads Sub cerca_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles cerca.Click
        apriAna.Value = 0
        ViewState("filtro") = Trim(txNome.Text)
        aggGrid()
    End Sub

    Private Sub cerca2_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles cerca2.Click
        apriAna.Value = 0

        ViewState("filtro") = Trim(txNumero.Text)
        aggGridperNumero()
    End Sub

    Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Response.Write("<SCRIPT language='javascript'>window.open('stampaCandidatiEsame.aspx','_blank','width=600,height=400,toolbar=no,location=no,menubar=no,resizable=yes,status=no,titlebar=no,scrollbars=yes,directories=no') </SCRIPT>")

    End Sub


End Class
